package edu.mobbuzz.web.pages;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;

import edu.mobbuzz.daf.bean.Rss;
import edu.mobbuzz.web.base.SecureBasePage;
import edu.mobbuzz.web.facade.ManagementFacade;

public class RssFormPage extends SecureBasePage{
	@Property
	private Rss rss;
	@Component
	private Form rssForm;
	private ManagementFacade managamentFacade;		

	public ManagementFacade getManagamentFacade() {
		if(managamentFacade==null)
			managamentFacade = new ManagementFacade();
		return managamentFacade;
	}

	void onActionFromClear(){
		rss = null;
		rssForm.clearErrors();
    }
	
	
	Object onSuccessFromRssForm(){
		if(rss.getUrl()==null){			
			getManagamentFacade().addRss(rss);
		}else{				
			getManagamentFacade().addRss(rss);		
		}
		rss = null;				
		return RssGridPage.class;
	}
	
	void onPrepare(){
    	if (rss == null){
    		rss = new Rss();
    	}        
    }
    
    void cleanupRender() {
    	rss = null;
	}
    
    
}
